package cn.tedu.front.job.dao.persist.repository.impl;

import cn.tedu.common.pojo.vo.PageData;
import cn.tedu.common.util.PageInfoToPageDataConverter;
import cn.tedu.front.job.dao.persist.mapper.PositionMapper;
import cn.tedu.front.job.dao.persist.repository.IPositionRepository;
import cn.tedu.front.job.pojo.entity.Position;
import cn.tedu.front.job.pojo.vo.*;
import cn.tedu.zhaopin.protocol.position.vo.PositionSimpleVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class PositionRepository implements IPositionRepository {
    @Autowired
    private PositionMapper mapper;

    @Override
    public Long addNew(Position position) {
        mapper.insertPosition(position);
       return position.getId();
    }

    @Override
    public int updateInfoById(Position position) {
        return mapper.updateById(position);
    }

    @Override
    public void deleteById(Long id) {
        mapper.deleteById(id);
    }

    @Override
    public PositionDetailVO getStandardById(Long id) {
        return mapper.selectDetailById(id);
    }

    @Override
    public PageData<PositionSimpleVO> list(Long userId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<PositionSimpleVO> list = mapper.list(userId);
        PageInfo<PositionSimpleVO> pageInfo = new PageInfo<>(list);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }

    @Override
    public RecruiterStanderVO getRecruiterByUserId(Long userId) {

        return mapper.getRecruiter(userId);
    }

    @Override
    public JobCategoryByIdVO getCategoryById(Long jobTypeId ) {
        return mapper.getCategoryById(jobTypeId);
    }

    @Override
    public PageData<PositionSimpleVO> listSearch(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<PositionSimpleVO> list = mapper.listSearch();
        PageInfo<PositionSimpleVO> pageInfo = new PageInfo<>(list);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }
}
